﻿<template>
	<el-dialog :title="!dataForm.id ? '新建' : '编辑'" :close-on-click-modal="false" :visible.sync="visible"
		class="SHZY-dialog SHZY-dialog_center" lock-scroll width="600px">
		<el-row :gutter="15" class="">
			<el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right"
				:rules="rules">
				<el-col :span="24">
					<el-form-item label="产线" prop="lineCode">
						<SHZY-select :list="lineCodeOptions" placeholder="请选择产线" v-model:bindValue="dataForm.lineCode"
							isConcat label="name" value="code" @change="GetLine"></SHZY-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="IP地址" prop="ipAddress">


						<SHZY-select :list="ipAddressOption" placeholder="请选择产线" v-model:bindValue="dataForm.ipAddress"
							label="ipAddress" value="ipAddress"></SHZY-select>


					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="录像类型" prop="ipType">

						<el-select v-model='dataForm.ipType' placeholder='请选择' clearable :style='{ "width": "100%" }'>
							<el-option v-for="(item, index) in ipTypes" :key="index" :label="item.fullName"
								:value="item.id"></el-option>
						</el-select>


					</el-form-item>
				</el-col>
				<!-- <el-col :span="24">
					<el-form-item label="摄像头状态" prop="status">
						<el-select v-model='dataForm.status' placeholder='请选择' clearable :style='{ "width": "100%" }'>
							<el-option v-for="(item, index) in statuslist" :key="index" :label="item.fullName"
								:value="item.id"></el-option>
						</el-select>
					</el-form-item>
				</el-col> -->
				<el-col :span="24">
					<el-form-item label="有效标志" prop="enabledMark">
					
						<el-switch v-model="dataForm.enabledMark" 
							:active-value = 1 :inactive-value = 0>
						</el-switch>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="操作人" prop="operateUserId">
						<user-select v-model='dataForm.operateUserId' placeholder='请选择' multiple clearable >
						</user-select>
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
import cameraManage from '@/api/q1/business/cameraManage';
export default {
	components: {},
	props: [],
	data() {
		return {
			btnLoading: false,
			loading: false,
			visible: false,
			dataForm: {
				id: '',
				lineCode: undefined,
				lineName: undefined,
				ipAddress: undefined,
				ipType: undefined,
				operateUserId: undefined,
				status: undefined,
				enabledMark: 1,
				creatorUserId: undefined,
				creatorTime: undefined,
			},
			ipTypes: [{ 'fullName': "主摄", 'id': "主摄" }, { 'fullName': "次摄", 'id': "次摄" }],
			statuslist: [{ 'fullName': "未开启", 'id': 0 }, { 'fullName': "录像中", 'id': 1 }],
			lineCodeOptions: [],
			ipAddressOption: [],
			rules: {
				lineCode: [
					{
						required: true,
						message: '请输入产线编码',
						trigger: "blur"
					}
				],
				lineName: [
					{
						required: true,
						message: '请输入产线名称',
						trigger: "blur"
					}
				],
				ipType: [
					{
						required: true,
						message: '请选择录像类型',
						trigger: "blur"
					}
				],
				status: [
					{
						required: true,
						message: '请选择摄像头状态',
						trigger: "blur"
					}
				],
				operateUserId: [
					{
						required: true,
						message: '请输入操作人',
						trigger: "blur"
					}
				],
				ipAddress: [
					{
						required: true,
						message: '请输入IP地址',
						trigger: "blur"
					}
				],
				enabledMark: [
					{
						required: true,
						message: '请选择是否有效',
						trigger: "blur"
					}
				],
			},
		}
	},
	computed: {},
	watch: {},
	created() {
	},
	mounted() {

		let query = {
			enabledMark: 1

		}
		cameraManage.qmsbasecameraline(query).then(res => {

			console.log(res)
			this.lineCodeOptions = res.data.list
		})

		cameraManage.qmsbasecameraip(query).then(res => {
			console.log(res)
			this.ipAddressOption = res.data.list
		})

	},
	methods: {
		goBack() {
			this.$emit('refresh')
		},
		init(id) {
			this.dataForm.id = id || 0;
			this.visible = true;
			this.$nextTick(() => {
				this.$refs['elForm'].resetFields();
				if (this.dataForm.id) {

					cameraManage.qmsbasecameralineipbyid(this.dataForm.id).then(res => {
						this.dataForm = res.data;

					})
				}
			});
			this.$store.commit('generator/UPDATE_RELATION_DATA', {})
		},
		dataFormSubmit() {
			this.$refs['elForm'].validate((valid) => {
				if (valid) {
					this.btnLoading = true;
					if (!this.dataForm.id) {

						cameraManage.addqmsbasecameralineip(this.dataForm).then(res => {

							this.$message({
								message: res.msg,
								type: 'success',
								duration: 1000,
								onClose: () => {
									this.btnLoading = false;
									this.visible = false,
										this.$emit('refresh', true)
								}
							})
						})

					} else {

						cameraManage.updateqmsbasecameralineip(this.dataForm).then(res => {
							this.$message({
								message: res.msg,
								type: 'success',
								duration: 1000,
								onClose: () => {
									this.btnLoading = false;
									this.visible = false
									this.$emit('refresh', true)
								}
							})

						})

					}
				}
			})
		},

		GetLine(val) {

			this.dataForm.lineName = this.lineCodeOptions.find(item => item.code == val).name
			console.log(this.dataForm.lineName)
		}
	}
}
</script>
